import allure
from selenium.webdriver.common.by import By

from base.base1 import Base


class PageLogin(Base):
    # 输入用户名
    @allure.step('1、输入用户名')
    def __input_username(self, username):
        self.element_send_keys((By.CSS_SELECTOR, '#username'), username)

    # 输入密码
    @allure.step('2、输入密码')
    def __input_password(self, password):
        self.element_send_keys((By.CSS_SELECTOR, '#password'), password)

    # 输入验证码
    @allure.step('3、输入验证码')
    def __input_code(self, code):
        self.element_send_keys((By.CSS_SELECTOR, '#verify_code'), code)

    # 点击登录
    @allure.step('4、点击登录')
    def __login_button(self):
        self.element_click((By.CSS_SELECTOR, '#loginform > div > div.login_bnt > a'))

    # 获取错误信息
    # #layui-layer1 > div.layui-layer-content.layui-layer-padding > i
    def get_error_message(self):
        return self.get_text((By.CSS_SELECTOR, 'div.layui-layer-content.layui-layer-padding'))

    def login(self, username, password, code):
        self.__input_username(username)
        self.__input_password(password)
        self.__input_code(code)
        self.__login_button()
